package cn.baddonkey;

import cn.baddonkey.settings.Settings;
import cn.baddonkey.ui.MainDialog;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.CommonDataKeys;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.Messages;
import org.apache.commons.lang3.StringUtils;

/**
 * @author junheng.zhou
 * @since 2022-06-27 16:25
 **/
public class VariableNameHelper extends AnAction {

    @Override
    public void actionPerformed(AnActionEvent event) {
        Editor editor = event.getRequiredData(CommonDataKeys.EDITOR);
        Project project = event.getRequiredData(CommonDataKeys.PROJECT);
        Settings settings = Settings.getInstance();
        if (settings == null
                || settings.getSettingMap() == null
                || StringUtils.isEmpty(settings.getSettingMap().get("accessKey"))
                || StringUtils.isEmpty("secretKey")) {
            Messages.showMessageDialog(project, "还未配置百度翻译API秘钥，请先前往File->settings->Other Settings->Variable Name Helper Setting（或直接搜索Variable Name Helper Setting）中配置", "Tips", Messages.getInformationIcon());
            return;
        }
        new MainDialog(editor, project);
    }
}
